﻿using System;
using System.Collections.Generic;
using System.Drawing.Imaging;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.SessionState;
using AiXiu.Common;
using AiXiu.BLL;
using AiXiu.IBLL;
using AiXiu.Model;
using System.Web.Security;

namespace AiXiu.WebSite
{
    public partial class Register : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void register_btn_Click(object sender, EventArgs e)
        {
            //txtYanZhengMa.Text.Equals(Session["Captcha"].ToString());
            if (Page.IsValid)
            {   
                //核对验证码
                if (Session["yzm"].ToString().Equals(txtYanZhengMa.Text))
                {
                    OperResult<TBUsers> oper = new LoginAndRegisterBLL().register(new TBLogins { 
                        UserName = txtAccount.Text,
                        MobileNumber = txtMobile.Text,
                        Password = txtPassword.Text
                    });

                    if (oper.StatusCode != 0)
                    {
                        this.Alert("error", oper.Message);
                        return;
                    }
                    IdentityManager.SaveUser(oper.Result);
                    string retUrl = Request.QueryString["ReturnUrl"];
                    this.AlertAndRedirect("tzIndex", "注册成功", string.IsNullOrWhiteSpace(retUrl) ? "IndexList.aspx" : retUrl);
                }
                else
                {
                    this.Alert("errorYzm", "验证码错误");
                }
            }
            else
            {
                this.Alert("errorRegister", "注册失败");
            }
        }
    }
}